package com.example.area.controller;

import com.example.area.service.AreaService;
import com.example.entity.Area;
import com.example.result.CommonResult;
import com.example.utils.MyPageHelper;
import com.example.utils.PageRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/area")
public class AreaController {
    @Autowired
    AreaService areaService;
    /**
     * 停车场管理-区域全查
     * @return
     */
    @GetMapping("/getArea")
    public CommonResult getArea(@RequestParam String areaName, PageRequest pageRequest){
        MyPageHelper.StartPage(pageRequest);
        CommonResult commonResult = areaService.getArea(areaName);
        return commonResult;
    }
    /**
     * 停车场管理-区域删除
     */
    @DeleteMapping("/delArea")
    public CommonResult delArea(Integer id){
        int i = areaService.delArea(id);
        return CommonResult.ok(i);
    }
    /**
     * 停车场管理-区域增改
     */
    @PostMapping("/saveOrUpdateArea")
    public CommonResult saveOrUpdateArea(@RequestBody Area area){
        int i = areaService.saveOrUpdateArea(area);
        if(i>0){
            return CommonResult.ok();
        }else{
            return CommonResult.fail();
        }
    }
}
